package com.crud.aspect;

import com.crud.datasource.DynamicDataSourceHolder;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;


@Component
@Aspect
@Order(1)
public class DataSourceAspect {

    @Before("@annotation(dataSource))")
    public void intercept(JoinPoint joinPoint, DataSource dataSource) throws NoSuchMethodException {
        DynamicDataSourceHolder.setDataSource(dataSource.value());
    }
}